//
//  UtilMacro.h
//  BSDemo
//
//  Created by kenshin on 7/3/14.
//  Copyright (c) 2014 BazzarEntertainment. All rights reserved.
//
#import "AppDelegate.h"


typedef void (^TKActionBlock)(id);
typedef void (^TKActionBlockString)(NSString *);
typedef void (^TKActionEmptyBlock)(void);
typedef void (^TKActionSuccessBlock)(BOOL);

#define FMT(format, ...) [NSString stringWithFormat:(format), ##__VA_ARGS__]

/*------------------------------屏幕/设备/操作系统等常量--------------------------*/

//设备系统相关
#define mIsPad    (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define mIsiphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define mSystemVersion   ([[UIDevice currentDevice] systemVersion])
#define mCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

#define APPBOUNDLEID [[NSBundle mainBundle] bundleIdentifier]
#define APPNAME [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]
#define APPVERSION [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]

/*判断设备是否是IPHONE5的屏幕*/
/*判断设备型号*/
#define mIPhone4s ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

#define mIPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define mIPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)

#define mIPhone6plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)) : NO)

#define iPhone5 mIPhone5

/*判断系统是否是IOS7*/
#define mIsIOS9 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0 ? YES:NO)
#define mIsIOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 ? YES:NO)
#define mIsIOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 ? YES:NO)
#define mIsIOS6 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0 ? YES:NO)
#define mIsIOS5 ([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0 ? YES:NO)

#define isIOS7 mIsIOS7
#define isIOS6 mIsIOS6


#define APISource		@"ios"

#define DeviceName		[[UIDevice currentDevice] name]
#define DeviceSys		[[UIDevice currentDevice] model]
#define DeviceModel		[[UIDevice currentDevice] localizedModel]
#define DeviceSdk		[[UIDevice currentDevice] systemName]
#define DeviceVersion	[[UIDevice currentDevice] systemVersion]


/*------------------------------方法简写--------------------------*/

#define mAppDelegate        (AppDelegate *)[[UIApplication sharedApplication] delegate]
#define CurrentAppDelegate mAppDelegate

#define mWindow             [[[UIApplication sharedApplication] windows] lastObject]
#define mKeyWindow          [[UIApplication sharedApplication] keyWindow]
#define mUserDefaults       [NSUserDefaults standardUserDefaults]
#define mNotificationCenter [NSNotificationCenter defaultCenter]

#define RootDirectory	[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

#define CacheDirectory	[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]

#define TmpDirectory	NSTemporaryDirectory()


//以tag读取View
#define mViewByTag(parentView, tag, Class)  (Class *)[parentView viewWithTag:tag]
//读取Xib文件的类
#define mViewByNib(Class, owner) [[[NSBundle mainBundle] loadNibNamed:Class owner:owner options:nil] lastObject]

//度弧度转换
#define mDegreesToRadian(x)      (M_PI * (x) / 180.0)
#define mRadianToDegrees(radian) (radian*180.0) / (M_PI)

//颜色转换
#define kSetColor(R,G,B,r) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:r]
#define mRGBColor(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]
#define mRGBAColor(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
//rgb颜色转换（16进制->10进制）
#define mRGBToColor(rgb) [UIColor colorWithRed:((float)((rgb & 0xFF0000) >> 16))/255.0 green:((float)((rgb & 0xFF00) >> 8))/255.0 blue:((float)(rgb & 0xFF))/255.0 alpha:1.0]

//简单的以AlertView显示提示信息
#define mAlertView(title, msg) \
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil \
cancelButtonTitle:@"确定" \
otherButtonTitles:nil]; \
[alert show];

//G－C－D
#define mGCDBackground(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define mGCDMain(block)       dispatch_async(dispatch_get_main_queue(),block)




#define APP_ASSERT_STOP                     {NSLog(@"APP_ASSERT_STOP"); NSAssert1(NO, @" \n\n\n===== APP Assert. =====\n%s\n\n\n", __PRETTY_FUNCTION__);}



#ifdef __IPHONE_6_0 // iOS6 and later
#   define UITextAlignmentCenter    NSTextAlignmentCenter
#   define UITextAlignmentLeft      NSTextAlignmentLeft
#   define UITextAlignmentRight     NSTextAlignmentRight
#   define UILineBreakModeTailTruncation     NSLineBreakByTruncatingTail
#   define UILineBreakModeMiddleTruncation   NSLineBreakByTruncatingMiddle
#endif
